<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>凡客商城后台管理</title>

    <!-- Bootstrap Core CSS -->
    <link href="{{asset('bower_components/bootstrap/dist/css/bootstrap.min.css')}}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="{{asset('bower_components/metisMenu/dist/metisMenu.min.css')}}" rel="stylesheet">

    <!-- Timeline CSS -->
    <link href="{{asset('dist/css/timeline.css')}}" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="{{asset('dist/css/sb-admin-2.css')}}" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="{{asset('bower_components/morrisjs/morris.css')}}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="{{asset('bower_components/font-awesome/css/font-awesome.min.css')}}" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <div id="wrapper">

        <!-- Navigation -->
        <!--包含顶部文件-->
        @include('admin.top')
        

                <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">详情</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            友情链接列表
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th>友联Id</th>
                                            <th>友联名</th>
                                            <th>友联地址</th>
                                            <th>联系人</th>
                                            <th>友联图片</th>
                                            <th>是否上线</th>
                                            <th>开始时间</th>
                                            <th>结束时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($flinks as $flink)
                                        <tr class="odd gradeX">
                                            <td>{{$flink['webid']}}</td>
                                            <td>{{$flink['webname']}}</td>
                                            <td>{{$flink['weburl']}}</td>
                                            <td>{{$flink['webtel']}}</td>
                                            <td><img src="{{asset($flink['weblogo'])}}" height="50" ></td>
                                            <td>{{$flink['isonline']}}</td>
                                            <td>{{$flink['starttime']}}</td>
                                            <td>{{$flink['endtime']}}</td>
                                    
                                            <td>
                                                <button data-id="{{$flink['webid']}}" class="update" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-pencil"></span></button>
                                                <button data-id="{{$flink['webid']}}" class="delete"><span class="glyphicon glyphicon-remove"></span></button>
                                            </td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                                {!! $flinks->appends(['type'=>'flinks'])->render() !!}
                            </div>

                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
 
        </div>
    
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form method="post" role="form" action="/admin/flink/update" class="form-horizontal" enctype="multipart/form-data">
    {!! csrf_field() !!}
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        商品信息详情
                    </h4>
                </div>
                <div class="modal-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">友链ID</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputEmail3" name="webid" readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">友联名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputEmail3" name="webname">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">友联地址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputEmail3" name="weburl">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">联系人</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputEmail3" name="webtel">
                            </div>
                        </div>  

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">友链图片</label>
                            <div class="col-sm-10">
                                <input class="form-control" name="weblogo" type="file"> 
                            </div>
                        </div>

                        <!--原商品照片-->
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                                <input type="hidden" class="form-control" id="inputEmail3" name="yimg" readonly>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">是否上线</label>
                            <input type="radio" name="isonline" value="是" checked="checked" />上线
                            <input type="radio" name="isonline" value="否"/>下线
                        </div>
                        
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">新上架时间</label>
                            <div class="col-sm-10">
                                <input type="datetime-local" class="form-control" id="inputEmail3" name="starttime">
                            </div>
                        </div> 

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">新下架时间</label>
                            <div class="col-sm-10">
                                <input type="datetime-local" class="form-control" id="inputEmail3" name="endtime">
                            </div>
                        </div> 

                    
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                            </button>
                            <button type="submit" class="btn btn-primary">
                                提交更改
                            </button>
                        </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </form>
    </div>
                

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="{{asset('bower_components/jquery/dist/jquery.min.js')}}"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="{{asset('bower_components/bootstrap/dist/js/bootstrap.min.js')}}"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="{{asset('bower_components/metisMenu/dist/metisMenu.min.js')}}"></script>
	<style>
		#dataTables-example_paginate{
			display:none;
		}
	</style>
    <!-- DataTables JavaScript -->
    <script src="{{asset('bower_components/datatables/media/js/jquery.dataTables.min.js')}}"></script>
    <script src="{{asset('bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js')}}"></script>

    <!-- Custom Theme JavaScript -->
    <script src="{{asset('dist/js/sb-admin-2.js')}}"></script>

    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    $(document).ready(function() {
        $('#dataTables-example').DataTable({
                responsive: true
        });
    });
    </script>
    
    <script>
        $(function(){

            //删除用户操作
            $('.delete').bind('click',function(){
                //获取删除的用户的ID
                var webid = $(this).attr('data-id');
                //确定用户操作
            

             if(!confirm('您确定要删除ID为:'+webid+'的友联吗')){
                    return false;
                };
                //alert(uid);
                var $btn = $(this);
                //ajax传送到服务器
                $.ajax({
                    url:'/admin/flink/delete',
                    data:'webid='+webid,
                    type:'get',
                    dataType:'text',
                    success:function(data){
                        //根据返回结果判断是否删除成功
                        if(data == 1){
                            //清除当前行
                            //找到tr标签进行删除操作
                            $btn.parents('tr').remove();
                        }else{
                            //失败警告
                            alert('删除失败');
                        }
                    }
                });

                //接收结果
            });

            //更新用户操作
            $('.update').bind('click',function(){
                //获取用户信息写入弹出框
                var webid = $(this).attr('data-id');
                //到数据库中获取数据 //革新用户界面
                //ajax传送到服务器
                $.ajax({
                    url:'/admin/flink/modify',
                    data:'webid='+webid,
                    type:'get',
                    dataType:'json',
                    success:function(data){
                        //将用户信息摆放到弹出框
                        console.log(data);
                        $('input[name="webid"]').val(data.webid);
                        $('input[name="webname"]').val(data.webname);
                        $('input[name="yimg"]').val(data.weblogo);
                        $('input[name="weburl"]').val(data.weburl);
                        $('input[name="webtel"]').val(data.webtel);
                    }
                });
            });
        });
    </script>

</body>

</html>
